#ifndef WEBSOCKETCLIENT_H
#define WEBSOCKETCLIENT_H

#include <QObject>
#include <QWebSocket>
#include <QUrl>
#include <QString>
#include <QJsonObject>

#include "message.h"

class WebSocketClient : public QObject
{
    Q_OBJECT
public:
    explicit WebSocketClient(QObject *parent = nullptr);

    void connectUrl(QString url);
    void sendTextMessage(const QString &message);
    void close();

signals:
    void signal_recvTextMessage(QString message);
    void signal_receiveTextMessage(Message);


private slots:
    void slot_connected();
    void slot_disconnected();
    void slot_recvTextMessage(QString message);
    void slot_receiveTextMessage(QString);

private:
    QWebSocket *m_webSocket;
    QUrl m_url;
    bool m_isConnected = false; // 为true表明已连接服务器，否则未连接上
    bool m_isSigningOut = false;

    void reconnect();
};

#endif // WEBSOCKETCLIENT_H
